package com.yaoli.ajob;



import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.Socket;
import java.net.UnknownHostException;

public class SendUpdateSewageIdTaskClient {

	//private static Logger logger = Logger.getLogger(SendUpdateSewageIdTaskClient.class);

	public static void main(String[] args) throws InterruptedException {
		SendUpdateSewageIdTaskClient sendUpdateSewageIdTaskClient = new SendUpdateSewageIdTaskClient();
		sendUpdateSewageIdTaskClient.sendSewageid(100);
	}

	
	public static void sendSewageid(int sewageid) throws InterruptedException{
		try {
			//Map<String, String> map = CustomPropertyConfigurer.getProperties();
			String ip = "61.147.198.178";//SystemConfig.others.get("sendipconfig");
			String port = "8791";//SystemConfig.others.get("sendipport");
			Socket socket =new Socket(ip,Integer.valueOf(port));
			OutputStream os=socket.getOutputStream();
			InputStream is=socket.getInputStream();

			byte[] req = new byte[3];
			int a = sewageid/127;
			int b = sewageid%127;
			req[0] = (byte)35;
			req[1] = (byte)a;
			req[2] = (byte)b;

			//接收服务器的相应
			byte [] reply = new byte[2];
			for (int j = 0; j < 2; j++) {
				os.write(req);
				os.flush();

				//读两次
				is.read(reply);
				 Thread.sleep(100L);
				//is.read(reply);
				if(reply[0] == 35 || reply[1] == 35){
					//重新再发一次，否则
					break;
				}else {
					//Thread.sleep(10000L);
				}
			}
			socket.shutdownOutput();
			is.close();
			os.close();
			socket.close();
			System.out.print("ok");
			//logger.info("江都站点id："+sewageid+", 时间修改成功");
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
